/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Game;

import GameClass.LoseScreen;
import GameClass.MainMenuScreen;
import GameClass.PlayingScreen;
import GameClass.SettingScreen;
import GameClass.WinScreen;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;

/**
 * @author THINH
 */
public class ShootBalloon extends MIDlet {
    
    private boolean midletPaused = false;
    private PlayingScreen playingScreen;
    private MainMenuScreen mainMenuScreen;
    private SettingScreen settingScreen;
    private WinScreen winScreen;
    private LoseScreen loseScreen;
    private boolean isSound = false;
    private int Gamelevel = 1;
    private boolean isPause = false;
    //<editor-fold defaultstate="collapsed" desc=" Generated Fields ">//GEN-BEGIN:|fields|0|
    //</editor-fold>//GEN-END:|fields|0|
    /**
     * The ShootBalloon constructor.
     */
    public ShootBalloon() {
        mainMenuScreen = new MainMenuScreen(this);
        playingScreen = new PlayingScreen(this);
        settingScreen = new SettingScreen(this);
        winScreen = new WinScreen(this);
        loseScreen = new LoseScreen(this);
    }

    //<editor-fold defaultstate="collapsed" desc=" Generated Methods ">//GEN-BEGIN:|methods|0|
    //</editor-fold>//GEN-END:|methods|0|
    //<editor-fold defaultstate="collapsed" desc=" Generated Method: initialize ">//GEN-BEGIN:|0-initialize|0|0-preInitialize
    /**
     * Initilizes the application.
     * It is called only once when the MIDlet is started. The method is called before the <code>startMIDlet</code> method.
     */
    private void initialize() {//GEN-END:|0-initialize|0|0-preInitialize
        // write pre-initialize user code here
        switchDisplayable(null, getMainMenuScreen());
//GEN-LINE:|0-initialize|1|0-postInitialize
        // write post-initialize user code here
    }//GEN-BEGIN:|0-initialize|2|
    //</editor-fold>//GEN-END:|0-initialize|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: startMIDlet ">//GEN-BEGIN:|3-startMIDlet|0|3-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Started point.
     */
    public void startMIDlet() {//GEN-END:|3-startMIDlet|0|3-preAction
        // write pre-action user code here
//GEN-LINE:|3-startMIDlet|1|3-postAction
        // write post-action user code here
    }//GEN-BEGIN:|3-startMIDlet|2|
    //</editor-fold>//GEN-END:|3-startMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: resumeMIDlet ">//GEN-BEGIN:|4-resumeMIDlet|0|4-preAction
    /**
     * Performs an action assigned to the Mobile Device - MIDlet Resumed point.
     */
    public void resumeMIDlet() {//GEN-END:|4-resumeMIDlet|0|4-preAction
        // write pre-action user code here
//GEN-LINE:|4-resumeMIDlet|1|4-postAction
        // write post-action user code here
    }//GEN-BEGIN:|4-resumeMIDlet|2|
    //</editor-fold>//GEN-END:|4-resumeMIDlet|2|

    //<editor-fold defaultstate="collapsed" desc=" Generated Method: switchDisplayable ">//GEN-BEGIN:|5-switchDisplayable|0|5-preSwitch
    /**
     * Switches a current displayable in a display. The <code>display</code> instance is taken from <code>getDisplay</code> method. This method is used by all actions in the design for switching displayable.
     * @param alert the Alert which is temporarily set to the display; if <code>null</code>, then <code>nextDisplayable</code> is set immediately
     * @param nextDisplayable the Displayable to be set
     */
    public void switchDisplayable(Alert alert, Displayable nextDisplayable) {//GEN-END:|5-switchDisplayable|0|5-preSwitch
        // write pre-switch user code here
        Display display = getDisplay();//GEN-BEGIN:|5-switchDisplayable|1|5-postSwitch
        if (alert == null) {
            display.setCurrent(nextDisplayable);
        } else {
            display.setCurrent(alert, nextDisplayable);
        }//GEN-END:|5-switchDisplayable|1|5-postSwitch
        // write post-switch user code here
    }//GEN-BEGIN:|5-switchDisplayable|2|
    //</editor-fold>//GEN-END:|5-switchDisplayable|2|

    /**
     * Returns a display instance.
     * @return the display instance.
     */
    public Display getDisplay() {
        return Display.getDisplay(this);
    }

    /**
     * Exits MIDlet.
     */
    public void exitMIDlet() {
        switchDisplayable(null, null);
        destroyApp(true);
        notifyDestroyed();
    }

    /**
     * Called when MIDlet is started.
     * Checks whether the MIDlet have been already started and initialize/starts or resumes the MIDlet.
     */
    public void startApp() {
        if (midletPaused) {
            resumeMIDlet();
        } else {
            initialize();
            startMIDlet();
        }
        midletPaused = false;  
       // getDisplay().setCurrent(playingScreen);
       playingScreen.startGame();
    }

    /**
     * Called when MIDlet is paused.
     */
    public void pauseApp() {
        this.getPlayingScreen().pause = true;
        midletPaused = true;
        
    }

    /**
     * Called to signal the MIDlet to terminate.
     * @param unconditional if true, then the MIDlet has to be unconditionally terminated and all resources has to be released.
     */
    public void destroyApp(boolean unconditional) {
        //Code here
        
        //Clear system
        System.gc();
    }
    
    //Customize code

    public void setCurrent(Displayable d){
        getDisplay().setCurrent(d);
    }
    /**
     * @return the mainMenuScreen
     */
    public MainMenuScreen getMainMenuScreen() {
        mainMenuScreen.setFullScreenMode(true);
        return mainMenuScreen;
    }

    /**
     * @return the playingScreen
     */
    public PlayingScreen getPlayingScreen() {
            playingScreen.pause = false;
            //playingScreen = new PlayingScreen(this);
            return playingScreen;
    }

    /**
     * @return the settingScreen
     */
    public SettingScreen getSettingScreen() {
        return settingScreen;
    }

    /**
     * @param mainMenuScreen the mainMenuScreen to set
     */
    public void setMainMenuScreen(MainMenuScreen mainMenuScreen) {
        this.mainMenuScreen = mainMenuScreen;
    }

    /**
     * @param playingScreen the playingScreen to set
     */
    public void setPlayingScreen(PlayingScreen playingScreen) {
        this.playingScreen = playingScreen;
    }

    /**
     * @param settingScreen the settingScreen to set
     */
    public void setSettingScreen(SettingScreen settingScreen) {
        this.settingScreen = settingScreen;
    }
    
    public void setSound(boolean t)
    {
        isSound = t;
    }
    
    public boolean getSound()
    {
        return isSound;
    }
    
    public void setLevel(int l)
    {
        Gamelevel = l;
    }
    
    public int getLevel()
    {
        return Gamelevel;
    }

    /**
     * @return the loseScreen
     */
    public LoseScreen getLoseScreen() {
        return loseScreen;
    }

    /**
     * @return the winScreen
     */
    public WinScreen getWinScreen() {
        return winScreen;
    }

    /**
     * @param loseScreen the loseScreen to set
     */
    public void setLoseScreen(LoseScreen loseScreen) {
        this.loseScreen = loseScreen;
    }

    /**
     * @param winScreen the winScreen to set
     */
    public void setWinScreen(WinScreen winScreen) {
        this.winScreen = winScreen;
    }
    
    public boolean getPause()
    {
        return isPause;
    }
    
    public void setPause(boolean pause)
    {
        isPause = pause;
    }
}
